Cloud Storage
#GoogleCloud
順序
Listing objects  |  Cloud Storage  |  Google Cloud
which are ordered in the list lexicographically by name
辞書順のみっぽい
filename の頭の / はどちらかというといらない
/hoge/fuga のファイルを書こうとすると / というディレクトリが作られる
問題なく使えるけど要らない
https://gyazo.com/0c508b57acf3dc1733dfe043208c9f81
メモリ上のデータをアップロードする
https://cloud.google.com/nodejs/getting-started/using-cloud-storage?hl=ja#upload_to_cloud_storage
めも、バイナリにに限らず似たような感じで
code:upload_stream.ts
import { Readable } from 'stream';
import { Storage, File } from '@google-cloud/storage';
function uploadFile(
bucket: string,
path: string,
image: Buffer,
contentType: string = 'image/png'
): Promise<File> {
const file = storage.bucket(bucket).file(path);
const writer = file.createWriteStream({
metadata: { contentType },
});
const reader = new Readable();
reader.push(image);
reader.push(null);
return new Promise((resolve, reject) => {
reader
.on('error', reject)
.pipe(writer)
.on('error', reject)
.on('finish', () => resolve(file));
});
}
暗号化の話おもろい
デフォルトの暗号化でも内部では90日以下でキーのローテーションしていて最大20バージョンまで持ってる
90 * 20 / 365 = 4.9 で5年に1回は鍵のローテーションのために再暗号化される
google/keyczar: Easy-to-use crypto toolkit
昔のやつ、いまは Tink
Tink と Cloud KMS を使用したクライアントサイド暗号化  |  Cloud KMS ドキュメント  |  Google Cloud
デフォルトの保存データの暗号化  |  Security  |  Google Cloud Documentation
Google Managed Encryption Key
As per the cloud documentation1 KMS can automatically rotate KEKs (key encryption key) at regular time intervals, using Google’s common cryptographic library to generate new keys. The actual rotation schedule for a KEK varies by service, but the standard rotation period is 90 days. Google Cloud Storage specifically rotates its KEKs every 90 days.
バケットロック
バケットロック  |  Cloud Storage  |  Google Cloud
保持ポリシーの変更や削除を防ぐ、保存期間 n 年 てきなもの守る
主にコンプライス要件への対応に使う
バケットの保持ポリシーのロックは元に戻すことができません。
署名付き URL を発行する
署名付き URL  |  Cloud Storage  |  Google Cloud
roles/iam.serviceAccountTokenCreator が要る
元々自身のトークンを発行する権限もないので
code:iam.tf
resource "google_service_account_iam_member" "sa_token_creator" {
service_account_id = google_service_account.sa.name
role = "roles/iam.serviceAccountTokenCreator"
member = google_service_account.sa.member
}
こういうのを GAE に立てて IAP かけておくと許可したユーザに GCS のファイルを配れるので便利
gcsproxy / main.go
snippets
Python
gcsfs で読む
GCSFS — GCSFs 2023.12.2post1+1.g8e500c6.dirty documentation
code:gcsfs.py
import gcsfs
fs = gcsfs.GCSFileSystem()
fs.open(uri, 'r').read()